<template>
  <view style="padding: 10px;">
    <view>文件上传</view>
    <u-button text="上传" @click="chooseImage"></u-button>
    <image :src="image_path"></image>
    <view style="height: 50px"></view>
    <button @click="getData">请求数据</button>
    <view>{{ text }}</view>
    <button @click="getData1">请求数据1</button>
    <view>{{ text1 }}</view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      image_path: '',
      text: '',
      text1: '',
    }
  },
  onLoad() {

  },
  methods: {
    getData() {
      uni.request({
        url: 'https://www.jianshu.com/users/recommended?seen_ids=&count=5&only_unfollowed=true',
        data: {},
        header: {
          'Cookie': '_ga=GA1.2.1355910522.1655806737; UM_distinctid=18185c5bab12ff-01b1be9f7370c6-26021b51-154ac4-18185c5bab21059; __yadk_uid=e3yxLajkVMiXsMToMLKYZERt9dcahZ8A; _gid=GA1.2.217606207.1662437193; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2218311cf385954f-030e548395f451-26021c51-1395396-18311cf385a121c%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22%24device_id%22%3A%2218311cf385954f-030e548395f451-26021c51-1395396-18311cf385a121c%22%7D; locale=zh-CN; Hm_lvt_0c0e9d9b1e7d617b3e6842e85b9fb068=1662000986,1662115680,1662437193,1662511795; _m7e_session_core=046ee13bb5ab5420d9c1d54a5cf2dd2a; Hm_lvt_1c6cd6a9fd5f687d8040b44bebe5d395=1662000990,1662115682,1662437196,1662511797; Hm_lpvt_1c6cd6a9fd5f687d8040b44bebe5d395=1662511911; acw_tc=0b62600616625146599526992e0168391aa7ced1f364930af11146d1e0e506; acw_sc__v2=6317f5e3535032671e50b23f5badcd1e12795644; read_mode=day; default_font=font2; CNZZDATA1279807957=1345377447-1662449280-https%253A%252F%252Fwww.jianshu.com%252F%7C1662514090; acw_sc__v3=6317f5fb3a4fd1f19f8045cd31d72cc4a8798962; _gat=1; signin_redirect=https%3A%2F%2Fwww.jianshu.com%2F; Hm_lpvt_0c0e9d9b1e7d617b3e6842e85b9fb068=1662514779; ssxmod_itna2=Yq0xgQG=0=iQnRDl4iTT9bExAIK1o4DKNExq4G9bVtDBLhTe7pKGObfo8FAC5IxApKuKlkK6NUA=j9+p4oIDKRO9jx6o5f=gppBDjQoUpo07sLatSjvQ6=wGLI=sbVjlInFHst2IR=I8EOysep5rnQGNDEAY/mBQ/D5=R1FkUmTp0iqP7Uir2xq5b+g=uifCsGfEK0fpeQwLR2hLlloEqinTomWfU7itqiuT=Y4z+Iij=DIr2iWKPg+qRtuWx=Diq1i=W0xtu1ayFg5AGRlCqyKI7qWtgrrb0OH9XKt2jkTp++6LU8v=bPV7FED7tQKVADC8DijqPtYrQ0CW7=9psGwvQ7CBv=DajDYEQHSlYV+clb5=zHSDR5TyhKYouqAtgiDcVlw67gCRrKZqEiY+tq2IqElWzDbN2Fa4ekADxlxEK47DFWlmr+ciR2TCaF=aWaGA7AijhP285bIiDLkbMXUTqvqHNkzR2iK81w+5vqAUkhKTkwS=q41ZyePbjU9zNPlebYdCiQ8B7CCbxDKTeUDDLxD2ehDD; ssxmod_itna=YqRx9CiQeDqBPGImdOQqi=oYDv1xw+4GXmiDZDiqAPGhDCRO6MOGowhqBIrQKGOADhDmre/amGU+SBlkeqAt44B3DEx06sqC02xGGzxBYDQxAYDGDDPDohPD1D3qDkD7x6kguaqi3DEG5DROPDuc5GDGaCAoFGDeKD0p+aDQKhAxDrFP7CW/9N7Ii4AxG1e40H7C3qAxoffR0174fA/=+7DlKUDC9CdSKpDBR8grvstQiroMi=zhroVmD5exmxiihxtp2N771HqAw4SQ2eNWUDD=' //自定义请求头信息
        },
        success: (res) => {
          console.log("getData-success", res);
          this.text = res.data;
        }
      });
    },
    getData1() {
      uni.request({
        url: 'https://gitee.com/notifications/unread_count',
        data: {},
        header: {
          'Cookie': 'oschina_new_user=false; sensorsdata2015jssdkchannel=%7B%22prop%22%3A%7B%22_sa_channel_landing_url%22%3A%22%22%7D%7D; remote_way=http; user_locale=zh-CN; visit-gitee--2022-08-05%2011%3A32%3A30%20%2B0800=1; visit-gitee--2022-08-11%2017%3A05%3A59%20%2B0800=1; slide_id=9; remember_user_token=BAhbCFsGaQOgdQhJIiIkMmEkMTAkWS92R1JpbFp6b1JPbmlUTWVFcnNQdQY6BkVUSSIXMTY2MjA4NDI3Ny42MTAyODA1BjsARg%3D%3D--b331b2b3c6d8087422d0f56e0ed6927f2892941d; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22554400%22%2C%22first_id%22%3A%22182fbda134550f-09ffca0f977e358-26021c51-1395396-182fbda1346d7f%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%22182fbda134550f-09ffca0f977e358-26021c51-1395396-182fbda1346d7f%22%7D; visit-gitee--2022-09-02%2014%3A18%3A53%20%2B0800=1; tz=Asia%2FShanghai; gitee_user=true; Hm_lvt_24f17767262929947cc3631f99bfd274=1662082702,1662452720,1662511373; gitee-session-n=N2tGTG5hVHdsR1BMMDBRSXl4Z2VHSnEzSndBRi9TM2VabHdycWREYnpBRmY4VmpGMkpLOHFLWUk5Q0JNUlpqbnpXQWxNN3Y4Zmw2VzQ3L1doNC9OYXdNd3dSVkthUXQwbWNUb016emV1aTkxYldlRVJPLzlwVGJIZ0YrUnVnOGticWxzSm9jY2xoMWZLcjFSamFRbmxrK0ZCMHJmVkFob0MxWkdlMFJOVUlHd2IyQTZVYlFFc3J4Z1c3MC8wVmQyWDJ1NFF4V05KWFFTRDZVZDM1QTkzODhFZFNuQ2Q0TXlYSVpKSElBa2M1M29HK2lzeHdRL2hacnB1Z1VxUTJ3ODlibUhDRlFjTkYxTmtaUE4weHNERXc9PS0tL2o2YWllOE5IU205b2YrYi9ON1lxZz09--3d21373bd8e28c2188d4d8778e51b83c1c714b84',
          'X-CSRF-Token':'5Y/rslrFNKfbdUxc/NWTZCCkEkCBlbknPhylXg5jWUYnqh+6OHNNAqMVAaSRXUejefcuh6M6utF9X2w4hVfWJw=='
        },
        success: (res) => {
          console.log("getData1-success", res);
          this.text1 = res.data;
        }
      });
    },
    chooseImage() {
      plus.gallery.pick(
          (path) => this.uploadFile(path),
          (err) => console.log("取消选择图片"),
          {filter: "image"});
    },
    uploadFile(path) {
      uni.showLoading({title: "上传中..."})
      let task = plus.uploader.createUpload("https://travel.enn.cn/ssop/api/cms-v2/file/upload",
          {method: "POST", priority: 100},
          (t, status) => {
            uni.hideLoading()
            // 上传完成
            if (status == 200) {
              uni.showToast({title: "上传成功！"})
              console.log("Upload success: " + JSON.stringify(t))
              let {responseText} = t
              let {data} = JSON.parse(responseText)
              console.log("responseText", responseText, data)
              this.image_path = data
            } else {
              console.log("Upload failed: " + status)
              uni.showToast({title: "上传失败！"})
            }
          }
      );
      task.addFile(path, {key: "multipartFile"});
      task.addData("string_key", "string_value");
      task.start();
    }
  }
}
</script>

<style>

</style>
